package com.cloudcentral.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cloudcentral.util.Utils;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Map;

/**
 * <p>
 * 探测任务24小时策略表
 * </p>
 *
 * @author Administrator
 * @since 2023-11-23
 */
@Data
@SuperBuilder
@JsonSerialize
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@TableName("sys_detect_strategy")
@Schema(name = "DetectStrategy", description = "探测任务24小时策略表")
public class DetectStrategy implements Serializable {

  @Schema(description = "ID")
  @TableId(type = IdType.AUTO)
  private Long id;

  @Schema(description = "任务ID")
  @TableField(keepGlobalFormat = true)
  private Long detectId;

  @Schema(description = "时段")
  @TableField(keepGlobalFormat = true)
  private Integer hour;

  @Schema(description = "功率")
  @TableField(keepGlobalFormat = true)
  private Integer power;

  @Schema(description = "额外参数(JSON)")
  @TableField(keepGlobalFormat = true)
  private String params;

  public Map<String, Object> toJson() {
    Map<String, Object> result = Utils.objectToMap(this);
    result.remove("params");
    if (StringUtils.isNotBlank(params)) result.putAll(JSON.parseObject(params));
    return result;
  }
}
